package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.service.ILoginService;
import com.itheima.service.IUserService;
import com.itheima.service.impl.UserDetailsServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
//@RequiredArgsConstructor
public class LoginController {
    @Autowired
    private ILoginService loginService;

    @PostMapping("/login")
//    @PreAuthorize("hasAnyAuthority('test')")
    public Result login(@RequestParam String username, @RequestParam String password) {
        log.info("开始根据用户名密码登录:");
        String jwt = loginService.login(username, password);
        return Result.success(jwt);
    }

    @GetMapping("/logout")
    public Result logout() {
        loginService.logout();
        return Result.success("退出成功:");
    }

}
